﻿using Prism.Unity;
using Prism.Ioc;
using Prism.Mvvm;
using System.Windows;
using System;
using System.Reflection;
using AnChao.WPF.Controls.Prism.Views;
using AnChao.WPF.Controls.Prism.ViewModels;
using AnChao.WPF.Controls.Prism.ViewModels.OhMyGod;
using AnChao.WPF.Controls.Prism.Core;
using AnChao.WPF.Controls.Prism;

namespace AnChaoWPFControlsPrism
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : PrismApplication
    {
        //设置启动起始页
        protected override Window CreateShell()
        {
            return Container.Resolve<MainWindow>();
        }

        protected override void RegisterTypes(IContainerRegistry containerRegistry)
        {

        }

        //通过IOC容器注册IApplicationCommands为单例
        protected override void RegisterRequiredTypes(IContainerRegistry containerRegistry)
        {
            base.RegisterRequiredTypes(containerRegistry);

            containerRegistry.RegisterSingleton<IApplicationCommands, ApplicationCommands>();
        }

        //注册子窗体模块
        protected override void ConfigureViewModelLocator()
        {
            base.ConfigureViewModelLocator();
            ViewModelLocationProvider.Register<MainWindowView, MainWindowViewModel>();
            ViewModelLocationProvider.Register<GetMonthDayView, GetMonthDayViewModel>();
            ViewModelLocationProvider.Register<GetHourTabView, GetHourTabViewModel>();
            ViewModelLocationProvider.Register<MainWindow, MainWindowViewTest>();
            //ViewModelLocationProvider.SetDefaultViewTypeToViewModelTypeResolver((viewType) =>
            //{
            //    var viewName = viewType.FullName.Replace(".Views.", ".ViewModels.OhMyGod.");
            //    var viewAssemblyName = viewType.GetTypeInfo().Assembly.FullName;   
            //    var viewModelName = $"{viewName}Test, {viewAssemblyName}";
            //    return Type.GetType(viewModelName);
            //});
        }
    }
}